﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BlueMarineWebClient.BlueMarineService;
using System.ServiceModel.Security;



namespace BlueMarineWebClient
{
    public partial class Search : System.Web.UI.Page
    {
        private ExternalServiceClient _searchService = new ExternalServiceClient("WSHttpBinding_IExternalService");
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            _searchService.ClientCredentials.UserName.UserName = "";
            _searchService.ClientCredentials.UserName.Password = "";
            _searchService.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
            //bool ensureSearch = true; 
            DateTime inDate = DateTime.Parse(txtDateFrom.Text); 
            DateTime outDate = DateTime.Parse(txtDateTo.Text);
            int roomTypeId = 0;
            int minPrice = Int32.Parse(ddlPriceFrom.SelectedValue); 
            int maxPrice = Int32.Parse(ddlPriceTo.SelectedValue);
            bool view = false;
            bool bath = false;
            bool balcony = false;
            List<vRoomInfo> result = _searchService.SearchRoom(inDate, outDate, roomTypeId, minPrice, maxPrice, view, bath, balcony);
            if (result.Count > 0)
            {
                lblResult.Text = "Result";
                dlRoomType.DataSource = result;
                dlRoomType.DataBind();
            }
            else
            {
                lblResult.Text = "No Room Matched";
            }

          
        }

        void BindData()
        {
            dlRoomType.DataSource = null;
            dlRoomType.DataBind();
        }        
    }
}